package com.spring.housing1.controller.commen;

import com.spring.housing1.constant.ServiceTokenRequired;
import com.spring.housing1.constant.isNull;
import com.spring.housing1.returnType.CommenResult;
import com.spring.housing1.pojo.DoctorInfo;
import com.spring.housing1.pojo.RoomInfo;
import com.spring.housing1.server.UpdateServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;

/*
 * 更新接口
 * */
@RestController
public class UpdateController {



    @Autowired
    UpdateServer updateServer;
    private final Logger log = LoggerFactory.getLogger(QueryControl.class);

    /**
* 医生更新信息操作   @isNull 空值校验，参数不为空
* */
    @ServiceTokenRequired
@PostMapping("/updateUsers")
@isNull({"user_name","real_name","cell_phone","enable","room_id","id","pass_word"})
    public CommenResult update(@RequestBody   DoctorInfo param){
           return    updateServer.upadte(param);
    }

    /**
     * 医生新增信息操作  @isNull 空值校验，参数不为空
     * */
    @ServiceTokenRequired
    @PostMapping("/insertUsers")
    @isNull({"user_name","real_name","cell_phone","enable","room_id","name","pass_word"})
    public CommenResult insertUsers(@RequestBody   DoctorInfo param){
        return    updateServer.insertUsers(param);
    }

    /**
     * 科室角色更新信息操作
     * @param roomInfo 角色信息
     * */
    @ServiceTokenRequired
    @PostMapping("/updateRoom")
    @isNull({"room_id","room","descs","enable"})
    public CommenResult updateRoom(@RequestBody   RoomInfo roomInfo){
        return    updateServer.updateRoom(roomInfo);
    }
    /**
     * 科室角色新增信息操作   @isNull 空值校验，参数不为空
     * */
    @ServiceTokenRequired
    @PostMapping("/insertRoom")
    @isNull({"room","descs","enable"})
    public CommenResult insertRoom(@RequestBody   RoomInfo roomInfo){
        return    updateServer.insertRoom(roomInfo);
    }


    /**@param 病单id
    *param2 影像结果
    * @param3 医生id
     * 说明 （open_id/病单id） 的格式，文件名为 (病单id_序列)格式
    * @fileUploadWithCards 多文件图片
    * 照片上传至ftp服务器--主动模式(异步线程池)
    * */
//    @ServiceTokenRequired
    @RequestMapping(value = "/upload/files",method = RequestMethod.POST)
    public CommenResult uploadFile(@RequestParam("file") MultipartFile[] fileUploadWithCards,
                                   @RequestParam("param") String param,@RequestParam("param2") String param2,@RequestParam("param3") String param3){
        return    updateServer.fileUpload(fileUploadWithCards,param,param2,param3);
    }
    /** 内外科医生处理
     * 文件路径为:/root/zhou_images/医师id/病单id/病单id_序列号(根据文件上传的个数判定)
     * {"param":?,"param2":?,"param3":?}
    * @param  病单id
     * @param2  处理结果
     * @param3 医生id
    * */
    @ServiceTokenRequired
    @isNull({"param","param2","param3"})
    @RequestMapping(value = "/doctorHandle/last",method = RequestMethod.GET)
    public CommenResult doctorHandle(@RequestParam Map<String,String > param){
        return    updateServer.doctorHandle(param);
    }

    /**
     * 管理员修改流程节点信息
     * @param  param 病单id{"node_id":?}
     * */
    @ServiceTokenRequired
    @GetMapping("/updateNodeInfo")
    @isNull({"node_id"})
    public CommenResult updateNodeInfo(@RequestParam Map<String,String > param){
        return    updateServer.updateNodeInfo(param);
    }

    /**
     * @param  node_id 病单id{"node_id":?}
     * 删除流程节点
     * */
    @ServiceTokenRequired
    @GetMapping("/delNodeInfo")
    @isNull({"node_id"})
    public CommenResult delNodeInfo(@RequestParam Map<String,String >  node_id){
        return    updateServer.delNodeInfo(node_id);
    }



}
